import React from 'react';
import { Switch, Route, Redirect } from 'react-router-dom'
import BeforeEach from './beforeEach'
const Routerview = (props) => {
  const { routes } = props
  return (
    <Switch>
      {
        routes.length > 0 && routes.map((v, i) => {
          console.log(v);
          return (
            v.path 
              ? <Route path={v.path} key={i}
                render={ props => <BeforeEach { ...props } { ...v }></BeforeEach> }></Route>
              : <Redirect from={v.from} to={v.to} key={i}></Redirect>
          )
        })
      }
    </Switch>
  );
}

export default Routerview;
